package com.xd.spring.liteflow.component;

import cn.hutool.core.util.RandomUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component("gender")
@Slf4j
public class SwitchGenderCmp extends NodeSwitchComponent {


    @Override
    public String processSwitch() throws Exception {
        String name = Thread.currentThread().getName();
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        StackTraceElement stackTraceElement = stackTraceElements[1];
        String className = stackTraceElement.getClassName();
        String methodName = stackTraceElement.getMethodName();
        int lineNumber = stackTraceElement.getLineNumber();
        log.info("{} {} {} {} {} begin", name, className, methodName, lineNumber, System.currentTimeMillis());
        TimeUnit.SECONDS.sleep(1);
        log.info("{} {} {} {} {} end", name, className, methodName, lineNumber, System.currentTimeMillis());
        boolean b = RandomUtil.randomBoolean();
        return b ? "a" : "b";
    }


}
